<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" v-show="showSearch" :inline="true">
      <el-form-item label="用户名" prop="username">
        <el-input
          v-model="queryParams.username"
          placeholder="请输入"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="币种" prop="currency">
        <el-select
          v-model="queryParams.currency"
          placeholder="请选择"
          clearable
          size="small"
          style="width: 240px"
        >
          <el-option
            v-for="dict in currencyOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="请选择"
          clearable
          size="small"
          style="width: 240px"
        >
          <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="交易区间">
        <el-date-picker
          v-model="dateRange"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
    </el-row>
    <el-row>
      <el-col>
        <el-table v-loading="loading" :data="roleList">
          <el-table-column label="用户名" prop="username"   v-if="columns[0].visible"/>
          <el-table-column label="是否标记" prop="testFlag"  v-if="columns[1].visible">
            <template slot-scope="scope">
              <span>{{scope.row.testFlag == '1'?'是':'否'}}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作人员" prop="createBy"  v-if="columns[2].visible"/>
          <el-table-column label="币种" prop="currency"  v-if="columns[3].visible"/>
          <el-table-column label="申请数量" prop="applyAmount"  v-if="columns[4].visible"/>
          <el-table-column label="手续费" prop="commission"  v-if="columns[5].visible"/>
          <el-table-column label="提现数量" prop="actualAmount" v-if="columns[6].visible"/>
          <el-table-column label="提币地址" prop="address" width="200" show-overflow-tooltip v-if="columns[7].visible">
            <template slot-scope="scope">
              <el-popover
                placement="left"
                title=""
                width="100"
                trigger="hover">
                <img :src="sysAdom+scope.row.address"  alt="" width="100px">
                <span slot="reference"><svg-icon  icon-class="erweima" class-name="card-panel-icon" /></span>
              </el-popover>
              <span>{{ scope.row.address }}</span>
            </template>
          </el-table-column>
          <el-table-column label="状态" prop="status" :formatter="statusFormat" v-if="columns[8].visible"/>
          <el-table-column label="说明" prop="remark" show-overflow-tooltip v-if="columns[9].visible"/>
          <el-table-column label="交易时间" width="180" align="center" prop="createTime"  v-if="columns[10].visible">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.createTime) }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            width="90"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-button
                v-if="scope.row.status == '1'"
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
              >编辑</el-button>
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-col>

    </el-row>
    <!-- 添加或修改参数配置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="状态">
          <el-select
            v-model="form.status"
            placeholder="请选择"
            clearable
            size="small"
            style="width: 240px"
          >
            <el-option
              v-for="dict in statusOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="说明" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入说明" />
        </el-form-item>
        <el-form-item label="交易Hash" prop="hash" v-if="form.status=='2'">
          <el-input v-model="form.hash" placeholder="请输入交易hash"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { cashList, cashEdit} from "@/api/biz";

export default {
  name: "Cash",
  data() {
    return {
      sysAdom:process.env.VUE_APP_BASE_API+'/applyWithdraw/showQrCode/',
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      roleList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 币种状态数据字典
      currencyOptions: [
        {
          dictValue:'BTC',
          dictLabel:'BTC'
        },
        {
          dictValue:'USDT',
          dictLabel:'USDT'
        },
        {
          dictValue:'CRU',
          dictLabel:'CRU'
        },
        {
          dictValue:'XCH',
          dictLabel:'XCH'
        },
        {
          dictValue:'BZZ',
          dictLabel:'BZZ'
        },
        {
          dictValue:'PHA',
          dictLabel:'PHA'
        }
      ],
      // 状态数据字典
      statusOptions: [
        {
          dictValue:'1',
          dictLabel:'待审核'
        },
        {
          dictValue:'2',
          dictLabel:'已成功'
        },
        {
          dictValue:'3',
          dictLabel:'已撤销'
        }
      ],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        username: undefined,
        currency: undefined,
        status: undefined
      },
      // 表单参数
      form: {
        applyId:undefined,
        status: "1",
        remark: undefined,
        hash: undefined
      },
      // 列信息
      columns: [
        { key: 0, label: `用户名`, visible: true },
        { key: 1, label: `是否标记`, visible: true },
        { key: 2, label: `操作人员`, visible: true },
        { key: 3, label: `币种`, visible: true },
        { key: 4, label: `申请数量`, visible: true },
        { key: 5, label: `手续费`, visible: true },
        { key: 6, label: `提现数量`, visible: true },
        { key: 7, label: `提币地址`, visible: true },
        { key: 8, label: `状态`, visible: true },
        { key: 9, label: `说明`, visible: true },
        { key: 10, label: `交易时间`, visible: true }
      ],
      // 表单校验
      rules: {
        hash: [
          { required: true, message: "请输入交易hash", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    /** 查询申请提现列表 */
    getList() {
      this.loading = true;
      cashList(this.addDateRange(this.queryParams, this.dateRange)).then(
        response => {
          this.roleList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },

    // 表单重置
    reset() {
      this.form = {
        applyId:undefined,
        status: "1",
        remark: undefined,
        hash: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.open = true;
      this.title = '提现编辑';
      this.reset();
      this.form.applyId = row.id;
    },

    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          cashEdit(this.form).then(response => {
            this.msgSuccess("修改成功");
            this.open = false;
            this.getList();
          });
        }
      });
    }
  }
};
</script>
